let SPRTAG = cc.Enum({
    FLOWERTAG : 1,
    FLOWERTAG2 : 2
})
cc.Class({
    extends: cc.Component,

    properties: {
        sprFlower : cc.Node,
        sprFlower2 : cc.Node,
        bg : cc.Node,
        spr : {
            default : [],
            type : cc.SpriteFrame
        },
         singleLineText: {
            default: null,
            type: cc.EditBox,
        },
        errorLabel: cc.Node,
        webView: cc.Node,
        diaLog: cc.Node,
        goToEndBtn: cc.Node
    },

    // use this for initialization
    onLoad: function () {
       this.createBez(0);
       DialogStr = 6;

    },

    createBez(n) {
        this.controlPointsTo1 = [
            cc.p(191 - 280+n, 318-175+n),//控制点1
            cc.p(11 - 280+n, 131-175+n),//控制点2
            cc.p(271 - 280+n, 13-175+n)//终点
        ];
        this.bezierTo1 = cc.bezierTo(4.0,  this.controlPointsTo1);
        this.controlPointsTo2 = [
            cc.p((-1)*(191 - 280+n), 318 - 175+n),//控制点1
            cc.p((-1)*(11 - 280+n), 131 - 175+n),//控制点2
            cc.p((-1)*(271 - 280+n), 13 - 175+n)//终点
        ];
        this.bezierTo2 = cc.bezierTo(4.0,  this.controlPointsTo2);

        this.sprFlower.runAction(this.bezierTo1);
        this.sprFlower2.runAction(this.bezierTo2);

        this.sprFlower.y += n;
        this.sprFlower.x += n;
        this.sprFlower2.y += n;
        this.sprFlower2.x += n;

        this.schedule(this.flowerUpdate, 0.1);
	    this.schedule(this.flowerUpdate2, 0.1);
    },

    //创建I动作
    createI() {
        this.sprFlower.position = cc.p(-100, 300);
        this.sprFlower2.position = cc.p(-100,-250);

        let actionI = cc.sequence(cc.moveBy(1,200,0),cc.moveBy(0.5,-100,0),cc.moveBy(1,0,-150),cc.moveBy(0.5,-100,0),cc.moveBy(1,200,0));
        this.sprFlower.runAction(actionI);

        let actionU = cc.sequence(cc.moveBy(1.2,0,-180),cc.moveBy(1.5,200,0),cc.moveBy(1.2,0,180));
        this.sprFlower2.runAction(actionU);
        this.schedule(this.flowerUpdate, 0.1);
        this.schedule(this.flowerUpdate2, 0.1);
    },

    flowerUpdate() {
        let i = 1;
        i = Math.round(Math.random() * 18) + 1;
	    let sprFlower = this.sprFlower;
        let sprFlower2 = this.sprFlower2;

        let sprFlowerTmp = cc.instantiate(sprFlower);
        sprFlower.getComponent(cc.Sprite).spriteFrame = this.spr[i];
	    sprFlowerTmp.setPosition(sprFlower.getPosition());
	    this.bg.addChild(sprFlowerTmp);

	    if ( sprFlower.x == -9 && sprFlower.y == -162)
	    {  
		    this.unschedule(this.flowerUpdate);
		    this.unschedule(this.flowerUpdate2);
            this.createI();
	    }
        if (  Math.round(sprFlower.x) == 100 &&  Math.round(sprFlower.y) == 150)
	    {  
		    this.unschedule(this.flowerUpdate);
		    this.unschedule(this.flowerUpdate2);
            this.diaLog.active = true;
            this.singleLineText.node.active = true;
            this.goToEndBtn.active = true;
            // this.createI();
	    }
    },
    flowerUpdate2() {
        let i = 1;
	    i = Math.round(Math.random() * 18) + 1;
	    let sprFlower2 = this.sprFlower2;

	    let sprFlowerTmp = cc.instantiate(sprFlower2);
        sprFlowerTmp.getComponent(cc.Sprite).spriteFrame = this.spr[i];
	    sprFlowerTmp.setPosition(sprFlower2.getPosition());
	    this.bg.addChild(sprFlowerTmp);
    },

    goToEnd(){
        if(this.singleLineText.string ==  mima){
            this.webView.active = true;
        }else{
            this.errorLabel.active = true;
        }
    }
    // called every frame, uncomment this function to activate update callback
    // update: function (dt) {

    // },
});
